package cn.edu.jmu.oelp.controller;

import cn.edu.jmu.oelp.pojo.RespCode;
import cn.edu.jmu.oelp.pojo.RespEntity;
import cn.edu.jmu.oelp.pojo.ValidEntity;
import cn.edu.jmu.oelp.service.ValidEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashSet;
import java.util.List;

@RestController
@Transactional(rollbackFor=Exception.class)
public class ValidEntityController {
    @Autowired
    private ValidEntityService validEntityService;
    @RequestMapping("/findAllByParagraphsIdArticleIdAndCount/{id}/{id1}")
    public RespEntity findAllByParagraphsIdArticleIdAndCount(@PathVariable("id") int paragraphsId,@PathVariable("id1")int articleId){
       List<ValidEntity> list=validEntityService.findAllByParagraphsIdArticleIdAndCount(paragraphsId,articleId);
        if(list==null){
            return new RespEntity(RespCode.NULLDATA);
        }
        LinkedHashSet<ValidEntity> set =new LinkedHashSet<>();
       for(ValidEntity e: list){
           set.add(e);
       }
       return new RespEntity(RespCode.SUCCESS,set);
    }
}
